package com.example.swd1.gudong.main.user.runningrank;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.swd1.gudong.R;
import com.example.swd1.gudong.constant.Constant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by user on 9/12/16.
 */
public class RankListAdapter extends BaseAdapter {

    private Context context;

    public RankListAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return 1;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = View.inflate(context, R.layout.item_fragment_rank, null);
        ListView myView = (ListView) convertView.findViewById(R.id.lv_running_rank_me);
        ListView currentView = (ListView) convertView.findViewById(R.id.lv_running_rank_current);

        myView.setAdapter(new RankAdapter(context, loadMyRankData(), RankAdapter.MY_RANK));
        currentView.setAdapter(new RankAdapter(context, loadCurrentRankData(), RankAdapter.CURRENT_RANK));
        return convertView;
    }

    private List<Map<String, Integer>> loadMyRankData() {
        List<Map<String, Integer>> data = new ArrayList<>();
        HashMap<String, Integer> map = new HashMap<>(4);
        map.put(Constant.RANK, R.drawable.chat_rank_medal_3);
        map.put(Constant.ICON, R.drawable.avatar);
        map.put(Constant.NAME, R.string.name_one);
        map.put(Constant.DISTANCE, 1234);

        data.add(map);
        return data;
    }

    private List<Map<String, Integer>> loadCurrentRankData() {
        List<Map<String, Integer>> data = new ArrayList<>();
        HashMap<String, Integer> map;

        map = new HashMap<>(4);
        map.put(Constant.RANK, R.drawable.chat_rank_medal_1);
        map.put(Constant.ICON, R.drawable.avatar);
        map.put(Constant.NAME, R.string.name_two);
        map.put(Constant.DISTANCE, 5678);
        data.add(map);

        map = new HashMap<>(4);
        map.put(Constant.RANK, R.drawable.chat_rank_medal_2);
        map.put(Constant.ICON, R.drawable.avatar);
        map.put(Constant.NAME, R.string.name_three);
        map.put(Constant.DISTANCE, 3456);
        data.add(map);

        map = new HashMap<>(4);
        map.put(Constant.RANK, R.drawable.chat_rank_medal_3);
        map.put(Constant.ICON, R.drawable.avatar);
        map.put(Constant.NAME, R.string.name_one);
        map.put(Constant.DISTANCE, 1234);
        data.add(map);
        return data;
    }
}
